package com.jemframework.utils.stringformatter;

import java.util.ArrayList;
import java.util.List;

public class XXX_YYY_StringFormatter extends AbstractStringFormatter {

  public XXX_YYY_StringFormatter() {
    super();
  }

  protected int computeEndPosition(int i, Integer[] positions, String string) {
    if (i < positions.length - 1) {
      return positions[i + 1] - 1;
    } else {
      return string.length();
    }
  }

  protected Integer[] getTokensStartPositions(String string) {

    List<Integer> positions = new ArrayList<Integer>();
    positions.add(0);

    for (int i = 1; i < string.length(); i++) {
      if (string.charAt(i) == '_') {
        positions.add(i + 1);
      }
    }

    return positions.toArray(new Integer[positions.size()]);
  }

  protected void formatToken(StringBuffer out, String token, int tokens, int index) {
    out.append(token.toUpperCase());
    if (index < tokens - 1) {
      out.append('_');
    }
  }
}
